﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            Common.CMDCalc.outputReadstr += Outputstr;
        }

        private void Outputstr(string str)
        {
            try
            {
                Invoke(new MethodInvoker(() => {
                    this.textBox2.Text += str;
                }));
            }catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public int logthread(int m,int n)
        {
            for(int i = 0; i < m; i++)
            {
                Common.Log.Info(i.ToString());
            }
            return m;
        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Link;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void listBox1_DragLeave(object sender, EventArgs e)
        {

        }

        private void listBox1_DragOver(object sender, DragEventArgs e)
        {

        }

        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {

        }

        enum state
        {
            a=1,
            b=2,
            c=3
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox2.Text += Common.CMDCalc.ExcuteCommands(dSkinTextBox1.Text);
        }

        public void DoBat()
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            string targetDir = string.Format(@"D:\bat\");

            proc.StartInfo.WorkingDirectory = targetDir;
            proc.StartInfo.FileName = "servicerestart.bat";
            proc.StartInfo.Arguments = string.Format("10");

            proc.Start();
            proc.WaitForExit();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Common.CMDCalc.ExitCMD();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Startup(true);
            Common.MSSetup.SetStartup(true);
        }


        private void button3_Click(object sender, EventArgs e)
        {
            Common.MSSetup.SetStartup(false);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            sbyte[] b = {-1,-1 };
            int xxxx = b[0] | b[1];
            int ix = b[0];
            uint ui = (uint)ix;
            uint xxa = (uint)0xFFFFFFFF;
            int iaa = 0x7FFFFFFF-1;
            short iss = (short)xxxx;
            byte[] c = Array.ConvertAll(b, (a) => (byte)a);
            int sx = (short)((b[1] << 8 ) | b[0]);
            int sy = ((short)((b[1] << 8))) + b[0];
            int sz = (short)((b[1] << 8) + b[0]);
            int sw = (short)(b[1] << 8) | (short)b[0];
            double xx = (double)10 / 3;
        }

        public void getb(byte a)
        {

        }
    }
}
